﻿using Sustainalytics.Claims;
using Sustainalytics.Entities;
using System;
using System.Collections.Generic;
using System.Web.Http;

namespace Sustainalytics.ScreeningTool.Service
{
    public class CriteriaLevel2Dto
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string ShortName { get; set; }
        public bool IsEnabled { get; set; }
        public Guid CriteriaLevel1Id { get; set; }
        public List<object> BaseCriteria { get; set; }

        private CriteriaLevel2Dto()
        {
        }

        public static CriteriaLevel2Dto CreateComplete(CriteriaLevel2 criteriaLevel2, List<BaseCriteria> baseCriteria, bool isEnabled, ApiController controller, IClaimsChecker claimsChecker)
        {
            if (criteriaLevel2 == null)
                throw new ArgumentNullException("CriteriaLevel2", "CriteriaLevel2 cannot be null.");

            return new CriteriaLevel2Dto()
            {
                Id = criteriaLevel2.Id,
                Name = criteriaLevel2.Name,
                CriteriaLevel1Id = criteriaLevel2.CriteriaLevel1Id,
                BaseCriteria = baseCriteria.ConvertAll<object>(c => TemplateCriteriaDto.CreateWithNameIdType(controller, claimsChecker, c)),
                IsEnabled = isEnabled && baseCriteria.Count > 0,
                ShortName = criteriaLevel2.ShortName
            };
        }

        public static object CreateWithNameId(CriteriaLevel2 criteriaLevel2)
        {
            if (criteriaLevel2 == null)
                throw new ArgumentNullException("CriteriaLevel2", "CriteriaLevel2 cannot be null.");

            return new
            {
                Id = criteriaLevel2.Id,
                Name = criteriaLevel2.Name,
                ShortName = criteriaLevel2.ShortName,
                IsEnabled = true
            };
        }
    }
}
